//////////////////////////////////////////////////////////////////////////

#ifndef _TIMER_H_
#include "timer.h"
#endif

//////////////////////////////////////////////////////////////////////////

#include <boost/asio.hpp>
//#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

//////////////////////////////////////////////////////////////////////////


void Timer::Sleep( size_t _milliseconds )
{
    boost::asio::io_service io_service;

    // Construct a timer without setting an expiry time.
    boost::asio::deadline_timer timer(io_service);

    // Set an expiry time relative to now.
    timer.expires_from_now(boost::posix_time::milliseconds(_milliseconds));

    // Wait for the timer to expire.
    timer.wait();


    // Also this implementation is possible
    /*boost::xtime xt;
    boost::xtime_get(&xt, boost::TIME_UTC);
    xt.sec += _milliseconds / 1000;
    xt.nsec += (_milliseconds % 1000) * 1000000;

    boost::thread::sleep(xt);*/
}


//////////////////////////////////////////////////////////////////////////


size_t Timer::GetCurrTime()
{
    boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time();
    return static_cast<size_t>( now.time_of_day().total_milliseconds() );
}


//////////////////////////////////////////////////////////////////////////
